home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '90 / MacHack 90 Contest Entries / DragWindow by Ricardo ƒ / DragW.c < prev    next >
Encoding:
Text File  |  1990-06-15  |  1.8 KB  |  50 lines  |  [TEXT/MPS ]

  1. // NewDragWindow, Copyright © 1990 Ricardo Batista
  2. // This code gets installed during system startup by an INIT, the purpose is to
  3. // replace the old DragWindow routine with our code so that a window is moved
  4. // along with it's contents as supposed to moving around an outline only.
  5. //
  6. // This code is for MPW C 3.1, when compiled into a resource the SysHeap and
  7. // Locked bits need to be set in the resource attributes.
  8. //
  9. // After compiling copy this resource into a file that includes DragW INIT
  10. //
  11.  
  12. #include "Types.h"
  13. #include "Windows.h"
  14.  
  15. // we accept the same parameters as DragWindow, called by all Mac applications
  16.  
  17. pascal void NewDragWindow(WindowPtr w, Point pt, Rect *bounds)
  18. {
  19.     Point OldPoint, NewPoint, OffsetPoint;
  20.     short h, v;
  21.     GrafPtr savePort;
  22.     
  23.     GetPort(&savePort);                                // save the current port
  24.     SetPort(w);                                        // set coordinate system to window
  25.     OldPoint = NewPoint = pt;                        // make local copies of current mouse
  26.     OffsetPoint.h = w->portRect.left;                // stuff top-left of window in point
  27.     OffsetPoint.v = w->portRect.top;
  28.     LocalToGlobal(&OffsetPoint);                    // convert too global coordinates
  29.     OffsetPoint.h = pt.h - OffsetPoint.h;            // this offset is from window to mouse
  30.     OffsetPoint.v = pt.v - OffsetPoint.v;
  31.     while (StillDown()) {                            // is mouse still down ?
  32.         GetMouse(&NewPoint);
  33.         LocalToGlobal(&NewPoint);                    // whe now ?
  34.         if (PtInRect(NewPoint, bounds)) {            // respect application boundaries
  35.             if ((NewPoint.h != OldPoint.h) || (NewPoint.v != OldPoint.v)) {
  36.                 h = NewPoint.h - OffsetPoint.h;        // calculate new position of window
  37.                 v = NewPoint.v - OffsetPoint.v;        // using the offset of mouse-window
  38.                 MoveWindow(w, h, v, false);            // just do it
  39.                 OldPoint = NewPoint;                // save new 'old' location
  40.             }
  41.         }
  42.     }
  43.     SetPort(savePort);                                // restore coordinate system
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
  50.